function report(link, fakeid, action_type){
    var parse_link = parseUrl(link);
    if(parse_link == null)
    {
      return ;
    }
    var query_obj = parseParams( parse_link['query_str'] );
    query_obj['action_type'] = action_type;
    query_obj['uin'] = fakeid;
    var report_url = '/mp/appmsg/show?' + jQuery.param( query_obj );
    jQuery.ajax({
      url: report_url,
      type: 'POST',
      timeout: 2000
    })
 };
function share_scene(link, scene_type) {
	// Android无法会截取encode的参数，所以改用直接添加参数的方式
	var share_url = link + '&scene=' + scene_type;
	return share_url;
};
(function() {
	var desString = "优惠惊喜享不停";
	var search = window.location.search;

	var onBridgeReady = function() {
		var link = window.location.protocol + "//"
				+ window.location.host + window.location.pathname + search;

		link = link.replace("{", "%7B");
		link = link.replace("}", "%7D");
		var appId = '', title = htmlDecode('【微商城】关注我吧！更多会员特权等着你！'), desc = htmlDecode(desString),
		imgUrl = '', fakeid = "Mjc2OTgzMTM1", desc = desc || link;

		// 发送给好友; 
		WeixinJSBridge.on('menu:share:appmessage', function(argv) {
			WeixinJSBridge.invoke('sendAppMessage', {
				"appid" : appId,
				"img_url" : imgUrl,
				"img_width" : "640",
				"img_height" : "640",
				"link" : share_scene(link, 1),
				"desc" : desc,
				"title" : title
			}, function(res) {
				report(link, fakeid, 1);
			});
		});
		// 分享到朋友圈;
		WeixinJSBridge.on('menu:share:timeline', function(argv) {
			report(link, fakeid, 2);
			WeixinJSBridge.invoke('shareTimeline', {
				"img_url" : imgUrl,
				"img_width" : "640",
				"img_height" : "640",
				"link" : share_scene(link, 2),
				"desc" : desc,
				"title" : title
			}, function(res) {
			});
		});
		// 分享到微博;
		var weiboContent = '';
		WeixinJSBridge.on('menu:share:weibo', function(argv) {
			WeixinJSBridge.invoke('shareWeibo', {
				"content" : title + share_scene(link, 3),
				"url" : share_scene(link, 3)
			}, function(res) {
				report(link, fakeid, 3);
			});
		});
		// 隐藏右上角的选项菜单入口;
		//WeixinJSBridge.call('hideOptionMenu');
	};
	if (document.addEventListener) {
		document.addEventListener('WeixinJSBridgeReady', onBridgeReady,
				false);
	} else if (document.attachEvent) {
		document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
		document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
	}
})();